package com.application.chiettinhdienluc.app;

import android.app.Application;
import android.content.Context;

import com.application.chiettinhdienluc.data.GlobalData;
import com.application.chiettinhdienluc.data.SharedPreferencesData;
import com.application.chiettinhdienluc.db.MySQLiteHelper;
import com.application.chiettinhdienluc.model.NguoiDungModel;

public class MainApplication extends Application{
	private static final String MAIN_PROCESS = "com.application.chiettinhdienluc";
	protected static final String TAG = MainApplication.class.getSimpleName();
    private static Context context;	
    
    

    public static Context getAppContext() {
    	
        return MainApplication.context;
    }
    
    public static String getMaDonViQuanLy()
	{
    	//sharedPreferences = PreferenceManager.getDefaultSharedPreferences(context);
    	return SharedPreferencesData.getMaDonViQuanLy(context);				
	}
	
	public static String getLocalServerIp()
	{
		
		return SharedPreferencesData.getLocalServerIp(context);				 		
	}
	
	public static String getInternetServerIP()
	{
		
		return SharedPreferencesData.getInternetServerIp(context);				 		
	}
	
    private static boolean local_conntection = false;
	public static void setLocalConnect(boolean local)
	{		
		local_conntection = local;				 		
	}
	
	
	public static String getServerURL()	{ 
		
		if(local_conntection) {			
			return "http://" + SharedPreferencesData.getLocalServerIp(context) + ":" + SharedPreferencesData.getServicePort(context)  ;	
		} else {
			
			return "http://" + SharedPreferencesData.getInternetServerIp(context) + ":" + SharedPreferencesData.getServicePort(context)  ;	
			
		}	
					 		
	}
	
	
	
	
	private static String _maKhuVuc;
	
	public static String getMaKhuVuc()	{
	    	
	    	return _maKhuVuc;	
	}
	 
	 public static void setMaKhuVuc( String maKhuVuc)	{
	    	
	    	_maKhuVuc = maKhuVuc;	
	}
		
	 
	private static NguoiDungModel nguoidung;
	
	public static NguoiDungModel getNguoiDung()
	{
		return nguoidung;				 		
	}
	
	public static void setNguoiDung(NguoiDungModel nd)
	{
		nguoidung = nd;				 		
	}
	
	public static void logOut()
	{
		nguoidung = null;				 		
	}	

	public static String getQuyenNguoiDung()
	{
		return nguoidung.get_PhanQuyen();				 		
	}
	
	public static String getMaNVien()
	{
		return nguoidung.get_MaNVien();				 		
	}
	

	@Override
	public void onCreate() {
		// TODO Auto-generated method stub
		try {
			MainApplication.context = getApplicationContext();

			String dataPath = getApplicationContext().getFilesDir().getPath().replace("/files", "");
			GlobalData.initDataPath(dataPath);
			MySQLiteHelper.getInstance().cloneDataBase();
			
			GlobalData.getExternalStorageDirectory();
		} catch (Exception e) {
			// TODO: handle exception
		}
		super.onCreate();
	}

	@Override
	public void onLowMemory() {
		// TODO Auto-generated method stub
		super.onLowMemory();
	}
    
    
}